package match

import "fmt"

// UserMatchManagerRegion 总区域管理器
type UserMatchManagerRegion struct {
	RegionMap map[string]*userMatchManagerRegionUserManager `json:"region_map"`
}

// NewUserMatchManagerRegion 创建一个区域管理器
func NewUserMatchManagerRegion(regionList []string) *UserMatchManagerRegion {
	var regionMap = UserMatchManagerRegion{
		RegionMap: make(map[string]*userMatchManagerRegionUserManager),
	}
	for _, region := range regionList {
		regionMap.RegionMap[region] = newUserMatchManagerRegionUserManager(region)
	}
	return &regionMap
}

func (u UserMatchManagerRegion) Match(userId int64, region string) int64 {
	r, ok := u.RegionMap[region]
	if ok {
		return r.Match(userId)
	}
	fmt.Println("region not found")
	return 0
}

func (u UserMatchManagerRegion) Online(userId int64, region string) {
	r, ok := u.RegionMap[region]
	if ok {
		r.Online(userId)
	}
}

func (u UserMatchManagerRegion) Leave(userId int64, region string) {
	r, ok := u.RegionMap[region]
	if ok {
		r.Leave(userId)
	}
}
